<template>
  <div class="research">
    <div style="margin-bottom: 20px">
      <h1>科研情况表</h1>
      <el-tag>学号：{{ studentId }}</el-tag>
      <table>
        <thead>
        <tr>
          <th><input type="checkbox"></th>
          <th>序号</th>
          <th>姓名</th>
          <th>年龄</th>
          <th>性别</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item,index) in domains">
          <td><input type="checkbox"></td>
          <td>{{ index + 1 }}</td>
          <td>{{ item.researchType }}</td>
          <td>{{ item.researchName }}</td>
          <td>{{ item.researchTime }}</td>
          <td>
            <button>编辑</button>
            <button>删除</button>
          </td>
        </tr>
        </tbody>
      </table>


    </div>

  </div>
</template>
<script>
import {getStudentInfo, getResearch, submitResearchForm} from "@/api/student";

export default {
  data() {
    return {
      studentId: '',
      domains: [
        {
          researchType: '',
          researchTime: '',
          researchName: '',
          researchContent: '',
        },
      ],
      timestamp: '',
      loading: false,
    };
  },
  mounted() {
    getStudentInfo().then((res) => {
      console.log(res.data);
      this.studentId = res.data.studentId;
    });
    getResearch().then((res) => {
      console.log(res.data);
      this.domains = res.data;
    })
  },
  components: {},
  methods: {
    submitForm() {
      //console.log(this.$refs.formObj)
      // console.log(this.dynamicData.domains);
      //console.log(this.dynamicData.domains)
      for (let domain in this.dynamicData.domains) {
        const temp = this.dynamicData.domains[domain]
        if (temp.type === '' || temp.time === '' || temp.name === '' || temp.content === '') {
          this.$message.error("请填写必要的信息！")
          return
        }

      }
      this.timestamp = Date.now().toString();
      this.$nextTick(() => {
        this.$refs['formObj'].validate(valid => {
          console.log(valid)
          if (valid) {
            console.log(this.dynamicData.domains)
            this.loading = true;
            // 传给后端的值
            const params = {
              researchData: this.dynamicData.domains
            }
            submitResearchForm(params).then(res => {
              // console.log(res)
              // console.log(res.message)
              if (res.code === 50003) {
                this.$message.error(res.msg)
              } else {
                this.$message.success(res.msg)
              }
              this.loading = false
            })
          } else {
            //console.log("发生异常");
            this.$message.error("请按正确格式填写表单")
            //this.loading = false;
            return false;
          }
        });
      })
    },
    dynamicFormChange(data) {
      this.formResult = data;
      console.log('子组件传来的值', data)
    }
  }
};
</script>
<style>

.research {
  padding: 20px;
}
</style>
